package la.iok.hzsvn.lewin.movie.controller;

import la.iok.hzsvn.lewin.movie.core.Token;
import la.iok.hzsvn.lewin.movie.entity.MovieInstance;
import la.iok.hzsvn.lewin.movie.model.ClueCardGroupVo;
import la.iok.hzsvn.lewin.movie.service.ClueCardGroupInstanceService;
import la.iok.hzsvn.lewin.movie.service.MovieDownloadService;
import la.iok.hzsvn.lewin.movie.service.MovieInstanceService;
import la.iok.hzsvn.share.response.ListDataResponse;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("clueCardGroupInstances")
public class ClueCardGroupInstanceController {
    private final ClueCardGroupInstanceService clueCardGroupInstanceService;
    private final MovieDownloadService movieDownloadService;
    private final MovieInstanceService movieInstanceService;

    public ClueCardGroupInstanceController(ClueCardGroupInstanceService clueCardGroupInstanceService,
                                           MovieDownloadService movieDownloadService,
                                           MovieInstanceService movieInstanceService) {
        this.clueCardGroupInstanceService = clueCardGroupInstanceService;
        this.movieDownloadService = movieDownloadService;
        this.movieInstanceService = movieInstanceService;
    }

    /**
     * 查询剧本的所有线索分组
     * @param token 操作用户
     * @param id 剧本id
     * @return 线索分组列表
     */
    @GetMapping("movie/{id}")
    public ListDataResponse<ClueCardGroupVo> clueCardGroups(@RequestHeader Token token, @PathVariable Long id){
        return new ListDataResponse<>(clueCardGroupInstanceService.clueCardGroups(movieDownloadService.loadDownloadInstance(token,id)));
    }

    /**
     * 查询剧本的所有线索分组
     * @param id 剧本id
     * @param version 剧本版本
     * @return 线索分组列表
     */
    @GetMapping("movie/{id}/v/{version}")
    public ListDataResponse<ClueCardGroupVo> clueCardGroups2(@PathVariable Long id,@PathVariable String version){
        MovieInstance mi = movieInstanceService.movieInst2(id,version);
        return new ListDataResponse<>(clueCardGroupInstanceService.clueCardGroups(mi.getId()));
    }
}
